/**
 * Created by sa on 2016/9/22.
 * casperjs query-casperjs.js
 */
var casper = require('casper').create();
var mouse = require("mouse").create(casper);




casper.start();


casper.on('resource.requested', function (requestData, request) {
  if (requestData.url.indexOf('www.sogou.com/bill_un?') > 0) {
    this.echo("==============>page.resource.requested"+requestData.url);
    this.echo("==============>page.resource.requested"+request);
  }
});

casper.viewport(1024, 1024);

casper.thenOpen('http://www.kaikouyingyu.cn/sougou.html');


//保存追踪图片
casper.then(function () {

  console.log("then img1");

  this.echo(this.getCurrentUrl());

  var date = new Date()
  var pathP = 'sougou/30/1casperjs'
  pathP += date.valueOf() + '.png'

  this.capture(pathP, {
    top: 0,
    left: 0,
    width: 100,
    height: 18
  });
  console.log("tag save img ok");
});


casper.then(function () {
  console.log("mouseEvent");
  this.mouse.click(100, 5);
});


//保存追踪图片
casper.then(function () {

  console.log("then img2");
  this.echo(this.getCurrentUrl());
  var date = new Date()
  var pathP = 'sougou/30/2casperjs'
  pathP += date.valueOf() + '.png'

  this.capture(pathP, {
    top: 0,
    left: 0,
    width: 500,
    height: 500
  });
  console.log("tag save img ok");
});


casper.run(function () {
  console.log("run");
  this.echo(this.getCurrentUrl());
});
